package com.oracle.config.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.oracle.config.service.api.LoopImageApi;
import com.oracle.mapper.LoopimgMapper;
import com.oracle.pojo.Loopimg;
import com.oracle.vo.ResultEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.sql.Timestamp;
import java.util.Date;
import java.util.List;

@Service
public class LoopImageServiceImpl implements LoopImageApi {

    @Autowired
    private LoopimgMapper loopimgMapper;

    @Transactional(propagation = Propagation.REQUIRED,rollbackFor = Exception.class)
    @Override
    public ResultEntity addLoopImage(Loopimg loopimg) {
        loopimg.setCreatedate(new Timestamp(new Date().getTime()));
        loopimg.setModifydate(new Timestamp(new Date().getTime()));
        loopimg.setStatus(0);
        this.loopimgMapper.insertSelective(loopimg);
        return new ResultEntity(ResultEntity.CODE_SUCCESS,ResultEntity.MSG_SUCCESS);
    }

    @Transactional(propagation = Propagation.REQUIRED,rollbackFor = Exception.class)
    @Override
    public ResultEntity modifyLoop(Integer tag, Integer loopImageId) {
        Loopimg loopimg = new Loopimg();
        loopimg.setModifydate(new Timestamp(new Date().getTime()));
        loopimg.setId(loopImageId);
        loopimg.setLoop(tag);
        this.loopimgMapper.updateByPrimaryKeySelective(loopimg);
        return new ResultEntity(ResultEntity.CODE_SUCCESS,ResultEntity.MSG_SUCCESS);
    }

    @Transactional(propagation = Propagation.NOT_SUPPORTED,readOnly = true)
    @Override
    public ResultEntity<List<Loopimg>> findLoopImageAll() {
        List<Loopimg> loopimgList = this.loopimgMapper.selectByExample(null);
        return new ResultEntity<List<Loopimg>>(ResultEntity.CODE_SUCCESS,ResultEntity.MSG_SUCCESS,loopimgList);
    }

    @Transactional(propagation = Propagation.NOT_SUPPORTED,readOnly = true)
    @Override
    public int getCountLoop() {
        return this.loopimgMapper.selectCountLoop();
    }

}
